package com.fb;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.dev.IconViewClose;
import java.io.File;
import com.dev.MainActivity;

class OpenFileAs extends LinearLayout implements OnClickListener {
	WindowManager.LayoutParams wlp=new WindowManager.LayoutParams();
	File dest;
	TextView title;
	LinearLayout titlebar;
	IconViewClose ivc;
	LayoutParams tblp;
	MainActivity ma;
	OpenFileAs(MainActivity ma){
		super(ma);
		setOrientation(VERTICAL);
		setWillNotDraw(false);
		tblp=new LayoutParams(-1,ma.dialogTitleBarHeight);
		title=new TextView(ma){
			@Override
			public void onDraw(Canvas c){
				super.onDraw(c);
				Paint p=new Paint();
				p.setColor(FileBrowserPage.borderColor);
				c.drawRect(0,getHeight()-FileBrowserPage.borderWidth,getWidth(),getHeight(),p);
			}
		};
		title.setText("打开为：");
		title.setTextColor(0xff000000);
		title.setPadding(9,0,0,0);
		title.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
		ivc=new IconViewClose(ma);
		ivc.setOnClickListener(this);
		titlebar=new LinearLayout(ma){
			@Override
			public void onDraw(Canvas c){
				super.onDraw(c);
				Paint p=new Paint();
				p.setColor(FileBrowserPage.borderColor);
				c.drawRect(0,getHeight()-FileBrowserPage.borderWidth,getWidth(),getHeight(),p);
			}
		};
		titlebar.setWillNotDraw(false);
		titlebar.setOrientation(HORIZONTAL);
		titlebar.addView(title,new LayoutParams(0,-1,1));
		titlebar.addView(ivc);
		addView(titlebar,tblp);
	}
	@Override
	protected void onDraw(Canvas canvas){
		super.onDraw(canvas);
		Paint p=new Paint();
		p.setColor(FileBrowserPage.borderColor);
		canvas.drawColor(0xffffffff);
		canvas.drawRect(0,0,FileBrowserPage.borderWidth,getHeight(),p);
		canvas.drawRect(0,0,getWidth(),FileBrowserPage.borderWidth,p);
		canvas.drawRect(getWidth()-FileBrowserPage.borderWidth,0,getWidth(),getHeight(),p);
		canvas.drawRect(0,getHeight()-FileBrowserPage.borderWidth,getWidth(),getHeight(),p);
	}
	@Override
	public void onClick(View v){
		if(v==ivc){
			dismiss();
		}
	}
	void show(File dest){
		this.dest=dest;
		wlp.width=ma.gui.getWidth()*4/5;
		wlp.height=-2;
		ma.wm.addView(this,wlp);
	}
	void dismiss(){
		ma.wm.removeView(this);
	}
}
